package com.zfh.cloud.controller;

import com.zfh.cloud.pojo.Order;
import com.zfh.cloud.pojo.User;
import com.zfh.cloud.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

/**
 * Created by 小可乐$ on 2024/9/14$ 13:33$
 * description: user的controller
 */
@RestController
@RequestMapping("user")
public class UserController {
    @Autowired
    private UserService service;
    @Value("${server.port}")
    private String port;

    @PostMapping("/user/add")
    public boolean UserAdd(@RequestBody User user){
        return service.save(user);
    }

    @GetMapping("get/{userId}")
    public User findUserByUserId(@PathVariable(value = "userId") Long userId){
        return service.getById(userId);
    }
    /**
     * 根据userid查找order
     * */
    @GetMapping("getOrder/{userId}")
    public Order findOrderByUserId(@PathVariable(value = "userId") Long userId){
        return service.findOrderByUserId(userId);
    }
}
